(function ({form, table, layer, laydate, SelectDatas, appraisalTableIns, url, contentType, ok, AjaxFn, tablebtn, updataOpen, startAndForbid, optionfor}) {

    SelectDatas = ((obj) => (obj = AjaxFn(url + "appraisalSelectDatas", "", obj), {
        vappraisalsflg = '',
        vassessflg = ''
    } = obj, $("select[name=vappraisalsflg]").html(optionfor(vappraisalsflg, `<option value=""></option>`)), $("select[name=vassessflg]").html(optionfor(vassessflg, `<option value=""></option>`)), SelectDatas = obj))({}),
        form.render()

    appraisalTableIns = table.render({
        elem: '#appraisalTable',
        url: url + "appraisalTableDatas",
        method: 'post',
        contentType,
        page: {
            first: '首页',
            last: '尾页',
            prev: '上一页',
            next: '下一页',
            layout: ['count', 'prev', 'page', 'next'],
            groups: 5,
            theme: '#1e9fff',
            limits: [10, 20, 30, 40, 50],
        },
        cols: [
            [
                {title: '序号', type: 'numbers', fixed: "left", unresize: true, align: "center", width: 50, minWidth: 30},
                {
                    title: '操作',
                    fixed: "left",
                    unresize: true,
                    align: "center",
                    width: 220,
                    minWidth: 220,
                    templet: function (d, updata = '', look = '', start = '', forbid = '') {
                        updata = tablebtn({
                            "event": "updata",
                            "btnclass": "layui-btn layui-btn-xs updata-btn-color",
                            "icon": '&#xe642;',
                            "text": '修改',
                            "disabled": false
                        }),
                            look = tablebtn({
                                "event": "look",
                                "btnclass": "layui-btn layui-btn-xs ",
                                "icon": '&#xe6b2;',
                                "text": '查看',
                                "disabled": false
                            }),
                            forbid = d.vdelflg == '1' ?
                                tablebtn({
                                    "event": "start",
                                    "btnclass": "layui-btn layui-btn-xs start-btn-color",
                                    "icon": '&#xe683;',
                                    "text": '启用',
                                    "disabled": false
                                }) :
                                tablebtn({
                                    "event": "forbid",
                                    "btnclass": "layui-btn layui-btn-xs forbid-btn-color",
                                    "icon": '&#xe673;',
                                    "text": '禁用',
                                    "disabled": false
                                });
                        return '<div>' + updata + look + forbid + '</div>';
                    }
                },
                {field: 'vdelflgname', title: '状态', unresize: true, align: "center",width: 80, minWidth: 65},
                {field: 'vcontent', title: '评定内容', unresize: true, align: "center", minWidth: 300},
                {field: 'vappraisalsflgname', title: '评定类型', unresize: true, align: "center",width: 100, minWidth: 100},
                {field: 'vassessflgname', title: '考核类别', unresize: true, align: "center",width: 100, minWidth: 100},
                {field: 'vinsdate', title: '录入时间', unresize: true, align: "center", width: 160,minWidth: 160},
            ]
        ]
    }),

    table.on('tool(appraisalTable)',({data, event, tr})=>{
            //updata  look start forbid
            //{url, skin, title, tableIns, btns = ['取消', '修改']}
            event=='updata'?((obj=>(obj.url=url+`appraisalUpdataHtml/${data.vappraisalsid}`, obj.skin="appraisal-open", obj.title="考题修改", obj.tableIns=appraisalTableIns, obj.btns=['取消', '修改'], updataOpen(obj))))({}):
            event=='look'?((obj=>(obj.url=url+`appraisalLookHtml/${data.vappraisalsid}`, obj.skin="appraisal-look-open", obj.title="分值-查看", obj.tableIns=appraisalTableIns, obj.btns=['关闭'], updataOpen(obj))))({}):
            event=='start'?((obj)=>(
                obj.startAndForbid="启用",
                obj.masg="确定启用该考题吗？",
                obj.btns=['取消','启用'],
                obj.param=data,
                obj.tableIns=appraisalTableIns,
                obj.url=url+"appraisalStartAndForbid",
                startAndForbid(obj)
            ))({}):
            event=='forbid'?((obj)=>(
                obj.startAndForbid="禁用",
                obj.masg="确定禁用该考题吗？",
                obj.btns=['取消','禁用'],
                obj.param=data,
                obj.tableIns=appraisalTableIns,
                obj.url=url+"appraisalStartAndForbid",
                startAndForbid(obj)
            ))({}):""
        })

    form.on('submit(appraisalselect)', function ({field}) {
        appraisalTableIns.reload({
            where: field,
            page: {curr: 1}
        })
        return false;
    }),

    $("#appraisalAdd").click(c=>(c.url=url + "appraisalAddHtml",c.skin="appraisal-open",c.title="考题新增",c.tableIns=appraisalTableIns,c.btns=['取消', '保存'],updataOpen(c)))

})({
    form: layui.form,
    table: layui.table,
    layer: layui.layer,
    laydate: layui.laydate,
    SelectDatas: {},
    appraisalTableIns: '',
    url: "/evaluation/appraisal/",
    contentType: 'application/json;charset=utf-8',
    ok: function (msg, icon) {
        layui.layer.confirm(msg, {
            id: "ok",
            icon: icon,
            anim: 4,
            title: '提示',
            btn: ['确定'],
            closeBtn: false,
            success: function (layero) {
                var btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)';
                btn.focus();
            },
            yes: function (index, layero) {
                layer.close(index); //再执行关闭
            },
            end: function () {
                var index2 = parent.layer.getFrameIndex(window.name);
                parent.layer.closeAll();
            }
        });
    },
    AjaxFn: function (url, data, resource) {
        $.ajax({
            url,
            contentType: 'application/json;charset=utf-8',
            type: 'post',
            async: false,
            data,
            success: function (res) {
                let {msg='',code=''} =res;
                msg=='' && code==''? top.location.reload() : "";
                resource = res;
            }
        });
        return resource;
    },
    tablebtn: function ({event = "", btnclass = "layui-btn btncolor ", icon = "", text = "", disabled = false, btn = ""}) {
        disabled ? disabled = "disabled" : disabled = '';
        btn = `<button type="button" ${disabled} class="${btnclass}" lay-event="${event}"><i class="layui-icon">${icon}</i>${text}</button>`
        return btn;
    },
    updataOpen: function ({url, skin, title, tableIns, btns = ['取消', '修改']}) {
        layer.open({
                anim: 4, type: 2, skin: skin, resize: false,
                title: [title, 'font-size:18px; background-color:#e7eaec;'],
                area: ['aotu'],
                btn: btns,
                content: url,
                btn2: function (index, layero) {
                    var body = layer.getChildFrame('body', index);
                    body.find('#submit').click();
                    return false;
                },
                end: function () {
                    tableIns.reload();
                }
            }
        ), $(`.${skin} iframe`).css('height', '100%'),
            $(".layui-layer-btn").css({
                "padding-top": "0px",
                "padding-bottom": "3px",
                "background-color": "rgb(231, 234, 236)"
            });
    },
    startAndForbid: function ({startAndForbid, masg, btns, param, tableIns, url}) {
        layui.layer.confirm(masg, {
            id: "startAndForbid",
            icon: 3, anim: 4, title: '提示',
            btn: btns,
            success: function (layero) {
                let btn = layero[0].getElementsByClassName('layui-layer-btn')[0].getElementsByTagName('A')[0];
                btn.href = 'javascript:void(0)', btn.focus();
            },
            btn2: function (index, layero) {
                let {vdelflg, vappraisalsid} = param;
                param.vdelflg == "1" ? vdelflg = "0" : param.vdelflg == "0" ? vdelflg = "1" : "",
                    $.ajax({
                        url,
                        contentType: 'application/json;charset=utf-8',
                        type: 'post',
                        async: false,
                        data: JSON.stringify({vdelflg, vappraisalsid,startAndForbid}),
                        success: function (res) {
                            let {msg='',code=''} =res;
                            msg=='' && code==''? top.location.reload() :  code == 200 ? icon = 1 : icon = 5;
                            layer.msg(msg, {icon: icon});
                        }
                    })
            },
            end: function () {
                tableIns.reload();
            }
        });
    },
    optionfor: (vappraisalsflg, op) => {
        vappraisalsflg != '' ? $.each(vappraisalsflg, (i, item) => op += `<option value="${item.scode}">${item.vname}</option>`) : op = "";
        return op;
    },
})